package com.saclub.app.fragment;

import java.util.List;

import android.os.Bundle;
import android.view.View;
import butterknife.Bind;

import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.Animations.NoDescriptionAnimation;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.offroader.utils.StringUtils;
import com.saclub.app.R;
import com.saclub.app.activity.MyToolBarActivity;
import com.saclub.app.bean.part.News;
import com.saclub.app.common.MyPageHelper;

public abstract class CommonGirdFragment extends BaseProgressFragment<MyToolBarActivity> implements BaseSliderView.OnSliderClickListener {

	private List<News> newsList;

	@Bind(R.id.id_main_image_slider)
	protected SliderLayout slider;

	@Bind({ R.id.id_gird_item_1, R.id.id_gird_item_2, R.id.id_gird_item_3, R.id.id_gird_item_4, R.id.id_gird_item_5, R.id.id_gird_item_6 })
	protected List<View> girdItemViewList;

	@Override
	protected int obtainContentRes() {
		return R.layout.frag_common_gird_item;
	}

	@Override
	protected void initParams() {

	}

	@Override
	protected void initView() {
		//顶部轮转图
		slider.removeAllSliders();
		slider.setPresetTransformer(SliderLayout.Transformer.Default);
		slider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
		slider.setCustomAnimation(new NoDescriptionAnimation());
	}

	@Override
	public void onStart() {
		super.onStart();

		if (slider != null)
			slider.startAutoCycle();
	}

	@Override
	public void onStop() {
		super.onStop();

		// To prevent a memory leak on rotation, make sure to call stopAutoCycle() on the slider before activity or fragment is destroyed
		if (slider != null)
			slider.stopAutoCycle();
	}

	@Override
	public void onSliderClick(BaseSliderView slider) {

		//解析参数
		String url = slider.getBundle().getString("url");
		String title = slider.getBundle().getString("title");
		String newsJson = slider.getBundle().getString("news");

		//非法不处理
		if (StringUtils.isBlank(url))
			return;

		Bundle args = new Bundle();
		args.putString("news", newsJson);

		MyPageHelper.webView.showMyWebViewPage(getActivity(), url, title, args);
	}

	public SliderLayout getSlider() {
		return slider;
	}

	public List<View> getGirdItemViewList() {
		return girdItemViewList;
	}

	public List<News> getNewsList() {
		return newsList;
	}

	public void setNewsList(List<News> newsList) {
		this.newsList = newsList;
	}

}
